<?php
    session_start();
?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        // put your code here
        $productID = $_POST["productID"];
        $productQuantity = $_POST["quantity"];
        
        $con = mysql_connect("localhost", "zhouzhao", "19831022");
        if(!$con){
            die("could not connect to DB: ".mysql_error());
        }
        
        mysql_select_db("cloudcom", $con);
        
        if(isset($_SESSION["customerID"])){
            mysql_query("insert into shoppingCarts values (null, $productID, $productQuantity, '".$_SESSION["customerID"]."')");
        }else{
            mysql_query("insert into shoppingCarts values (null, $productID, $productQuantity, '".session_id()."')");
        }
        mysql_close($con);
        echo "new product $productID is inserted";
        
        require 'showCart.php';
        ?>
    </body>
</html>
